package com.example.spinning.utils;

import com.example.spinning.bean.User;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * Created by sang on 2017/12/20.
 */
public class Util {
    public static User getCurrentUser() {

        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();

//        if (principal instanceof UserDetails) {
//
//            String username = ((UserDetails)principal).getUsername();
//
//        } else {
//
//            String username = principal.toString();
//
//        }
        if("anonymousUser".equals(principal)){
            return null;
        }
        User user = (User)principal ;


        return user;
    }
}
